package pure.csw.activemq.persistence.topic;

import pure.csw.common.ActiveMqUtils;
import pure.csw.common.Constant;

import javax.jms.*;

public class Publisher {
    public static void main(String[] args) throws JMSException, InterruptedException {
        Connection connection = ActiveMqUtils.getConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(Constant.TOPICNAME);
        MessageProducer producer = session.createProducer(topic);
        //connection.start();
        System.out.println("发送消息。。。");
        for (int i = 0; i < 3; i++) {
            TextMessage message = session.createTextMessage();
            System.out.println("发送消息"+i);
            message.setText("message:"+i);
            producer.send(message);
        }
        producer.close();
        session.close();
        connection.close();
        System.out.println("程序结束");
    }
}
